import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import org.sherlock.commons.download.FetcherException;
import org.sherlock.downloader.Download;
import org.sherlock.downloader.DownloadManager;
import org.sherlock.downloader.DownloadsNotifier;
import org.sherlock.downloader.fetchers.FetcherFactory;

public class Main implements Observer {

	/**
	 * @param args
	 * @throws MalformedURLException
	 * @throws FetcherExceptionj
	 */
	public static void main(String[] args) throws MalformedURLException,
			FetcherException {
		new Main();
	}

	public Main() throws MalformedURLException, FetcherException {
		DownloadManager manager = new DownloadManager(2);
		DownloadsNotifier notifier = new DownloadsNotifier();
		notifier.addObserver(this);
		
		String localURL = "file:///Users/David/Desktop/Download";
		String remoteURL = "http://www.jhepple.com/SampleMovies/AVI_to_MPEG-4.avi";

		for (int i = 0; i < 10; i++) {
			Download download = new Download(new URL(localURL + (i + 1)), new URL(remoteURL));
			manager.addDownload(download);
			notifier.addDownload(download);
		}
	}

	@Override
	public void update(Observable o, Object arg) {
		System.out.println("----------------------");
		ArrayList<Download> downloads = (ArrayList<Download>) arg;
		for (Download download : downloads) {
			System.out.println(download.getFileName() + ": " + download);
		}
	}
}
